<template>
	<view class="shopDetails"> 
		<view class="shopDetails_content"  >
			 <tutor-videoImg-swiper :ossUrl="ossUrl" :imgUrls="imgUrls" ></tutor-videoImg-swiper>
			<view class="titleText">
				<view class="titleL">
					<view class="titleL_text"><text>{{tutorDetails.assistantName}}</text></view>
					<tui-form-button @click="goUserInfoEdit" margin="0 0 0 20rpx" width="120rpx" size="24" height="42rpx" plain background="#63d6d3" color="#63d6d3" radius="100rpx">
						<image class="icon" src="/static/tutor/order/icon_edit@2x.png"></image>编辑
					</tui-form-button> 
				</view>
				<view class="titleR">
					<text>{{tutorDetails.rates}}</text>
					<text class="priceTime">元/小时</text>
				</view>
			</view>
			<view class="tags">
				<view class="tag"><text>{{tutorDetails.personalSignature}}</text></view> 
			</view>
			<view class="timeText">
				<text>营业时间：{{tutorDetails.begintime}}—{{tutorDetails.endtime}}</text>
			</view>
			<view class="addressText">
			    教练地址：<text class="ct">{{tutorDetails.poi&&tutorDetails.poi.district}}</text>
			</view>
			<view class="tabList">
				<view class="tabList_tab">
					<tutor-tab :list="['最新动态','评价列表']" @clickSwtichTab="clickSwtichTab" :atciveIndex="atciveIndex"></tutor-tab>
				</view> 
				<view class="contentDynamic">
					<z-paging ref="paging" :fixed="false" v-model="listData" @query="queryList">
						<view class="shopImg" v-if="!atciveIndex">
							<!-- <text class="newest">最新动态</text>
							<view style="margin-top: 24rpx;margin-bottom: 40rpx;">
								 <tutor-dynamicItem :dynamicList="upDymicList" :ossUrl="ossUrl"></tutor-dynamicItem>
							</view>
							<text class="newest" >动态列表</text> -->
							<view>
								 <tutor-dynamicItem :dynamicList="listData" :ossUrl="ossUrl"></tutor-dynamicItem>
							</view>
						</view>
						<view class="appraiseItems" v-else>
								<tutor-appraiseItem :ossUrl="ossUrl" :listData="listData"></tutor-appraiseItem>
						</view>
					</z-paging> 
				</view>
		 
				 
			</view>
		</view> 
	</view>
</template>

<script>
	import { getTutorDetails } from "@/http/api/tutor/tutor.js"  
	import { getAppraiseList } from "@/http/api/appraise/appraise.js"  
	import { myDynamicList,myLoginDynamicList } from "@/http/api/dynamic/dynamic.js"
	export default {
		emits: [],
		props: { 
			//教练id
			id:{
				type:String,
				default:null
			},
			//oss链接
			ossUrl:{
				type:String,
				default:null
			}
		},
		data() {
			return { 
				isAgreement:false,
				listData:[],//评价数据
				upDymicList:[],//最新动态
				dymicList:[],//动态列表
				tutorDetails:{},//教练信息
				atciveIndex:0,//切换商家图片和教练列表
			}
		},
		computed:{
				imgUrls(){
					return  this.tutorDetails.detailImgs 
						// if(this.tutorDetails.detailImgs&&this.tutorDetails.detailImgs.length || false){ 
						// 	if(this.isImage(this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1])){
						// 		return  this.tutorDetails.detailImgs 
						// 	}else{
						// 		 return  this.tutorDetails.detailImgs.slice(0, -1)
						// 	}
						// }
					}, 
				// videoline(){
				// 	if(this.tutorDetails.detailImgs&&this.tutorDetails.detailImgs.length || false){  
				// 		if(this.isImage(this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1])){
				// 			 return ''
				// 		}else{
				// 			 return  this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1]
				// 		} 
				// 	}
				// }
			}, 
		mounted() {
		   this.getDetails() 
		   uni.$on('refresh',(e)=>{
		   	 if(e){
		   		 this.getDetails()
		   	 }
		   }) 
		},
		methods: { 
			isImage(filename) {
					const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg'];
					const fileExtension = filename.slice(filename.lastIndexOf('.'));
					return imageExtensions.includes(fileExtension.toLowerCase());
				},
			examine(arr, index) {
				uni.previewImage({
					urls: arr,
					current: index
				});
			},
			clickSwtichTab(data){
				this.atciveIndex= data.index
				this.$refs.paging.reload()
			},
			//获取教练详情
			getDetails(){
				getTutorDetails({id:this.id}).then(res=>{
					if(res.code===200){
					   this.tutorDetails=res.data
					}
					console.log(res,'获取当前教练信息')
				})
			},
			//加载动态和评价列表
			queryList(pageNo, pageSize) { 
				if(!this.atciveIndex){
					//获取最新动态
					// myLoginDynamicList({pageNum:pageNo,pageSize,queryType:2}).then(res => {
					// 	if (res.code == 200) {
					// 		  this.upDymicList=res.rows&&res.rows.slice(0,1) || [] 
					// 	} else {
					// 		this.$utils.toast(res.msg);
					// 	}
					// }) 
					myLoginDynamicList({pageNum:pageNo,pageSize,fromType:2,userId:this.tutorDetails.userId}).then(res => {
						if (res.code == 200) {
							  this.$refs.paging.complete(res.rows); 
						} else {
							this.$utils.toast(res.msg);
						}
					})
				}else{
					//获取教练评论
					 getAppraiseList({pageNum:pageNo,pageSize,commentType:2,beUserType:2,beUserId:this.tutorDetails.id}).then(res => {
					 	if (res.code == 200) { 
					 		 this.$refs.paging.complete(res.rows); 
					 	} else {
					 		this.$utils.toast(res.msg);
					 	}
					 }) 
				 }
			},
			//进入编辑页面
			goUserInfoEdit(){
			  let data=JSON.stringify(this.tutorDetails)
			   uni.navigateTo({
			   	url:'/pages/tutorControl/modules/userInfoEdit/userInfoEdit?tutorDetails='+data
			   })	
			}
		}
	}
</script>

<style lang="scss" scoped>
@import './tutorDetails.scss';
</style>